﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Samurai.Client.Windows
{
    /// <summary>
    /// Interaction logic for EditMovieWindow.xaml
    /// </summary>
    public partial class EditMovieWindow : Window
    {
        public EditMovieWindow()
        {
            InitializeComponent();

            DataContextChanged += new DependencyPropertyChangedEventHandler(EditMovieWindow_DataContextChanged);
        }

        void EditMovieWindow_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                var binding = new Binding();
                binding.Source = e.NewValue;
                binding.Path = new PropertyPath("IsClosed");
                this.SetBinding(IsClosedProperty, binding);
            }
        }

        public bool IsClosed
        {
            get { return (bool)GetValue(IsClosedProperty); }
            set { SetValue(IsClosedProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsClosed.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsClosedProperty =
            DependencyProperty.Register("IsClosed", typeof(bool), typeof(EditMovieWindow), new UIPropertyMetadata(false, new PropertyChangedCallback(ClosedPropertyChanged)));

        static void ClosedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var isClosed = (bool)e.NewValue;

            var window = (EditMovieWindow)d;

            if(isClosed)
                window.Close();
        }
    }
}
